package com.logicwin.aibala.com;

import java.io.File;

/**
 * 
 * 
 * @author GuoDing
 * @since 2011-07-29
 */
public final class GlobalConfig {
	private GlobalConfig() {
	}
	
	public static final String AIBALA_APKLIST_URL = "http://home.kequan001.com/aibala/getSoftwareList.php";
	
	public static final String  AUTOSTART = "autostarts";
	public static final String  AUTOSTARTED = "autostarted";
	public static final boolean DEFAULT_GENERAL_AUTOSTART = true;
	
	private static final String ROOT_DIR = "/sdcard/aibala";
	private static final String APK_DOWNLOAD_DIR = ROOT_DIR + "/apkDownload";
	private static final String IMG_CACHE_DIR = ROOT_DIR + "/imgcache";
	private static final String TEMP_DOWNLOAD_DIR = ROOT_DIR + "/temp";
	
	private static final String SQLITE_DB_NAME = "aibala_db";
	
	private static boolean isFirstInstall = false;
	
	/**
	 * 初始化，创建不存在的目录
	 * @throws AibalaException
	 */
	public static void init() {
		if(!checkDir(ROOT_DIR)) {
			isFirstInstall = true;
		}
		checkDir(APK_DOWNLOAD_DIR);
		checkDir(IMG_CACHE_DIR);
		checkDir(TEMP_DOWNLOAD_DIR);
	}
	
	public static String getAPKDownloadDir() {
		return APK_DOWNLOAD_DIR;
	}
	
	public static String getIMGCacheDir() {
		return IMG_CACHE_DIR;
	}
	
	public static String getTMPDownloadDir() {
		return TEMP_DOWNLOAD_DIR;
	}
	
	public static String getSQLiteDBName() {
		return SQLITE_DB_NAME;
	}
	
	public static boolean isFirstInstall() {
		return isFirstInstall;
	}
	
	private static boolean checkDir(String dir) {
		File f = new File(dir);
		if(!f.exists()) {
			f.mkdirs();
			return false;
		}
		return true;
	}
}
